home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / raw_nl1 / getrawnl.c < prev    next >
C/C++ Source or Header  |  1996-11-11  |  3KB  |  116 lines

  1. /*
  2. ** Access to RAW-Nodelist using NODELIST.RDX.
  3. **
  4. ** Copyright 1995 St.Slabihoud. Freeware.
  5. **
  6. ** You may copy and distribute this source, documentation and
  7. ** executable code as you receive it. You can use this source
  8. ** in your own programs.
  9. */
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <ext.h>
  15. #include <time.h>
  16. #include <portab.h>
  17. #include <defines.h>
  18.  
  19. #define VERSION    "0.01"
  20.  
  21. HEADER         header;
  22. NLHEADER    *nlheader;
  23. ENTRY         entry;
  24.  
  25. #define F_REGION    (1U << 0)
  26. #define F_HOST        (1U << 1)
  27. #define F_HUB            (1U << 2)
  28. #define F_PVT            (1U << 3)
  29. #define F_DOWN        (1U << 4)
  30. #define F_HOLD        (1U << 5)
  31. #define F_CM            (1U << 6)
  32. #define F_MO            (1U << 7)
  33.  
  34. #define M_V32T    (1U << 0)
  35. #define M_VFC     (1U << 1)
  36. #define M_HST     (1U << 2)
  37. #define M_PEP     (1U << 3)
  38. #define M_ZYX     (1U << 4)
  39. #define M_ISDNA   (1U << 5)
  40. #define M_ISDNB   (1U << 6)
  41. #define M_ISDNC   (1U << 7)
  42.  
  43.  
  44. int main(uword argc,ubyte *argv[])
  45. {    uword zone,net,node,point,i;
  46.     ubyte tmp[256];
  47.     FILE    *fp,*fptmp;
  48.     --argc;
  49.  
  50.     if (argc!=1)
  51.     {    fprintf(stderr,"GETRAWNL V"VERSION"   Nodelist-Utility (Demo)    (c) Stephan Slabihoud 1995\n\n\n");
  52.         fprintf(stderr,"Usage: getrawnl <4d-addr>\n");
  53.         getch();
  54.         exit(2);
  55.     }
  56.     printf("GETRAWNL V"VERSION"   Nodelist-Utility (Demo)    (c) Stephan Slabihoud 1995\n\n\n");
  57.  
  58.     strcpy(tmp,argv[1]);
  59.     sscanf(tmp,"%u:%u/%u.%u",&zone,&net,&node,&point);
  60.     printf("\nSearching for: %u:%u/%u.%u\n\n",zone,net,node,point);
  61.  
  62. /*
  63. ** Open Index-File
  64. */
  65.  
  66.     fp=fopen("NODELIST.RDX","rb");
  67.  
  68. /*
  69. ** Read Index-Header
  70. */
  71.  
  72.     fread(&header,sizeof(HEADER),1,fp);
  73.     printf("  Version: %u.%02u\n",header.version >> 8,header.version & 0xff);
  74.     printf("  Created: %s\n",ctime(&(time_t)header.datetime));
  75.     printf("Nodelists: %u\n",header.nodelists);
  76.     printf("   Sorted: %s\n\n",header.flag==0 ? "No" : "Yes (binary access possible)");
  77.  
  78. /*
  79. ** Now read all Nodelist-Header
  80. */
  81.  
  82.     nlheader = (NLHEADER *)malloc(sizeof(NLHEADER)*header.nodelists);
  83.     fread(&nlheader[0],sizeof(NLHEADER),header.nodelists,fp);
  84.     printf("Found following nodelists/pointlists:\n");
  85.     for (i=0; i<header.nodelists; i++)
  86.     {    printf("Day: %03u  - %s\n",nlheader[i].day,
  87.                                                                 *nlheader[i].network=='\0' ?
  88.                                                                         "unknown" : nlheader[i].network);
  89.     }
  90.     printf("\n");
  91.  
  92. /*
  93. ** And now search for the address. This could be done using the
  94. ** binary-search when all entries are sorted.
  95. */
  96.  
  97.     while(!feof(fp))
  98.     {    fread(&entry,sizeof(ENTRY),1,fp);
  99.         if (entry.zone==zone && entry.net==net &&
  100.                 entry.node==node && entry.point==point)
  101.         {    printf("Address found in: %s\n",nlheader[entry.nodelist].file);
  102.             printf("  List is a %s\n",nlheader[entry.nodelist].type==0 ? "Nodelist" : "Pointlist");
  103.             printf("  Flags: %x, %x\n",entry.f_flags,entry.m_flags);
  104.             fptmp=fopen(nlheader[entry.nodelist].file,"rb");
  105.             fseek(fptmp,entry.offset,SEEK_SET);
  106.             fgets(tmp,256,fptmp);
  107.             printf("  Entry: %s\n\n",tmp);
  108.             fclose(fptmp);
  109.         }
  110.     }
  111.  
  112.     free(nlheader);
  113.     fclose(fp);
  114.     return(0);
  115. }
  116.